<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<p:panel header="#{msg['massai.itemServico.header']}">
				<h:panelGrid columns="3">
					<h:panelGrid rendered="false">
						<h:outputLabel value="#{msg['massai.manterGrupoProducao.nivel']}" />
						<p:inputText tabindex="1" value="#{itemServicoBean.itemServico.nivel}" 
							style="text-align: right; width: 80px;" />
					</h:panelGrid>
					
					<h:panelGrid>
						<h:outputLabel value="#{msg['massai.itemServico.nivelPai']}" />
						<p:selectOneMenu tabindex="1" value="#{itemServicoBean.itemServico.nivelPai}" style="width: 250px;">
							<f:selectItems value="#{grupoProducaoBean.carregaItemPai()}" />
						</p:selectOneMenu>
					</h:panelGrid>
					
					<h:panelGrid>
						<h:outputLabel value="#{msg['massai.itemServico.unidadeMedida']}" for="unidade" />
						<p:selectOneMenu tabindex="2" id="unidadeMed" value="#{itemServicoBean.itemServico.unidadeMedida}" 
							label="#{msg['massai.itemServico.unidadeMedida']}" converter="entityConverter" style="width: 180px;">
							<f:selectItems value="#{itemServicoBean.unidadesMedida()}" />
						</p:selectOneMenu>
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid>
					<h:panelGrid>
						<h:outputLabel value="#{msg['massai.itemServico.descricao']}" />
						<p:inputText tabindex="4" value="#{itemServicoBean.itemServico.descricao}" style="width: 485px;" />
					</h:panelGrid>
				</h:panelGrid>
			</p:panel>
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton tabindex="5" value="#{msg['massai.comum.pesquisar']}"
						actionListener="#{itemServicoBean.pesquisar()}" update="form,:messages" />

					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>

		            <p:commandButton tabindex="6" value="#{msg['massai.comum.salvar']}" actionListener="#{itemServicoBean.salvar()}" ajax="false" update="form" />
		            
		            <span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>

		            <p:commandButton tabindex="7" value="#{msg['massai.comum.novo']}" action="itemServico" ajax="false" immediate="true" />
				</f:facet>
			</p:toolbar>

			<p:dataTable style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
				value="#{itemServicoBean.listaItemServico}" var="item" sortMode="multiple" rows="10" paginator="true"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                         currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">
				<f:facet name="header"><h:outputText value="#{msg['massai.itemServico.itensServico']}" /></f:facet>

				<p:column headerText="#{msg['massai.itemServico.nivelPai']}" sortBy="#{item.nivelPai}" width="80">
					<h:outputText value="#{item.nivelPai.descricao}" />
				</p:column>				

				<p:column headerText="#{msg['massai.manterGrupoProducao.nivel']}" sortBy="#{item.nivel}" width="60">
					<h:outputText value="#{genericUtilBean.completarZerosEsquerda(item.nivel, 6)}" />
				</p:column>

				<p:column headerText="#{msg['massai.itemServico.descricao']}" sortBy="#{item.descricao}">
					<h:outputText value="#{item.descricao}" />
				</p:column>

				<p:column headerText="#{msg['massai.itemServico.unidadeMedida']}" sortBy="#{item.unidadeMedida.sigla}" width="120">
					<h:outputText value="#{item.unidadeMedida.sigla} - #{item.unidadeMedida.descricao}" />
				</p:column>

				<p:column headerText="#{msg['massai.comum.editar']}" width="32" style="text-align: center;">
					<p:commandLink actionListener="#{itemServicoBean.atualizar()}" update=":form">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_edit.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.editar']}" 
							title="#{msg['massai.comum.editar']}" alt="#{msg['massai.comum.editar']}" />
						<f:param name="id" value="#{item.id}" />
					</p:commandLink>
				</p:column>
				
				<p:column headerText="#{msg['massai.comum.excluir']}" width="42" style="text-align: center;">
					<p:commandLink onclick="if (! window.confirm('Deseja excluir esse registro?') ) {return false}" 
						actionListener="#{itemServicoBean.remover()}" update=":form">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_remove.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.excluir']}" 
							title="#{msg['massai.comum.excluir']}" alt="#{msg['massai.comum.excluir']}" />
						<f:param name="id" value="#{item.id}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>
</html>